/**
 * 
 */
package wong.board.client.ui;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONObject;

/**
 * @author wong
 * 
 */
public class BookmarksPresenter extends Presenter<BookmarksPresenter.View, JSONObject> {

	public BookmarksPresenter() {
		this((View) GWT.create(View.class));
	}

	public BookmarksPresenter(View view) {
		super(view);
	}

	@Override
	public void updateView(JSONObject bookmarks) {
		// getView().resetBookmarks();
		Set<String> groupNames = bookmarks.keySet();
		for (String groupName : groupNames) {
			JSONObject group = bookmarks.get(groupName).isObject();
			HashMap<String, String> links = new HashMap<String, String>();
			Set<String> linkNames = group.keySet();
			for (String linkName : linkNames) {
				links.put(linkName, group.get(linkName).isString().stringValue());
			}
			getView().addLinks(groupName, linkNames, links);
			// getView().addLink(groupName,
			// bookmarks.get(groupName).isString().stringValue());
		}
	}

	public interface View extends Presenter.View {
		public void resetBookmarks();

		// public void addLink(String label, String url);

		public void addLinks(String label, Set<String> linkNames, Map<String, String> links);
	}

}
